package com.totcy.baselibrary.download;

import java.io.File;

/**
 * package : cn.adinnet.library.download<br>
 * description:<B>下载配置</B><br>
 * email : cookiexie@adinnet.cn<br>
 * date : 2015/12/4 10:12<br>
 *
 * @author Cookie Xie
 * @version v1.0
 */

public final class DownloadConfiguration {
    private boolean isOnlyWifiDownload;
    private File saveFilePath;
    private String title;
    private String description;
    private String version;

    private DownloadConfiguration(Builder builder) {
        this.isOnlyWifiDownload = builder.isOnlyWifiDownload;
        this.saveFilePath = builder.saveFilePath;
        this.title = builder.title;
        this.description = builder.description;
        this.version = builder.version;
    }

    public boolean isOnlyWifiDownload() {
        return isOnlyWifiDownload;
    }

    public File getSaveFilePath() {
        return saveFilePath;
    }

    public String getTitle() {
        return title;
    }

    public String getVersion() {
        return version;
    }

    public String getDescription() {
        return description;
    }

    public static class Builder {
        private boolean isOnlyWifiDownload;
        private File saveFilePath;
        private String title;
        private String description;
        private String version;

        public Builder() {
        }

        /**
         * 是否仅WIFI网络下下载
         * @param isOnlyWifiDownload true 仅WIFI下下载，使用数据流量不下载
         */
        public Builder setOnlyWifiDownload(boolean isOnlyWifiDownload) {
            this.isOnlyWifiDownload = isOnlyWifiDownload;
            return this;
        }

        /**
         * 设置保存路径，使用默认的就行，保存于sdcard/Android/data/包名/download目录下
         * @param saveFilePath 文件保存路径
         */
        public Builder setSaveFilePath(File saveFilePath) {
            this.saveFilePath = saveFilePath;
            return this;
        }

        /**
         * 设置下载标题
         * @param title 标题
         */
        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        /**
         * 设置下载描述，部分机器不会显示
         * @param description 描述
         */
        public Builder setDescription(String description) {
            this.description = description;
            return this;
        }

        /**
         * 设置版本
         * @param version 描述
         */
        public Builder setVersion(String version) {
            this.version = version;
            return this;
        }

        /**
         * 配置完成，创建配置
         * @return 配置
         */
        public DownloadConfiguration build() {
            return new DownloadConfiguration(this);
        }

        /**
         * 从已有的配置中克隆
         * @param configuration 配置
         */
        public Builder cloneFrom(DownloadConfiguration configuration) {
            isOnlyWifiDownload = configuration.isOnlyWifiDownload;
            saveFilePath = configuration.saveFilePath;
            title = configuration.title;
            description = configuration.description;
            return this;
        }

        /**
         * 默认配置
         */
        public Builder defaultConfiguration() {
            setOnlyWifiDownload(false);
//                    .setTitle("更新文件")
//                    .setDescription("下载完成是否打开");
//                    .setSaveFilePath(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS));
            return this;
        }
    }
}
